package cn.zhejianglao.shirotemplate.utils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class EncryptUtils {
    public static String hashStr(String inputStr) {
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        byte[] hash = digest.digest(inputStr.getBytes(StandardCharsets.UTF_8));
        StringBuilder hexString = new StringBuilder();
        for (byte b : hash) {
            String hexValue = Integer.toHexString(0xFF & b);
            if (hexValue.length() == 1) {
                hexString.append('0');
            }
            hexString.append(hexValue);
        }
        return hexString.toString();
    }
}
